import numpy as np

#def solve_displacements(K, F):
  #  displacements = np.linalg.solve(K, F)
  #  return displacements
import numpy as np

def solve_displacements(K, F):
    if np.linalg.det(K) == 0:
        print("矩阵 K 是奇异的，尝试使用伪逆")
        K_pinv = np.linalg.pinv(K)
        displacements = K_pinv.dot(F)
    else:
        displacements = np.linalg.solve(K, F)
    return displacements


